package org.msfj.toilets.data.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.msfj.common.base.BaseController;
import org.msfj.common.model.CommonResult;
import org.msfj.toilets.data.service.PositionInfoService;
import org.msfj.toilets.model.PositionInfo;
import org.msfj.toilets.vo.PositionInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 系统蹲位信息controller
 * @Author: like
 * @Email: like@deyatong.com
 * @Date: 2017-08-10 17:30:20
 * @Version: 1.0
 * @Created in idea by autoCode
 */
@Api(value = "系统蹲位信息接口", tags = "系统蹲位信息接口")
@RestController
@RequestMapping("org/positionInfo")
public class PositionInfoController extends BaseController {

    @Autowired
    private PositionInfoService positionInfoService;

    /**
     * 添加系统蹲位信息
     *
     * @param positionInfoVo
     * @return CommonResult.ok(PositionInfoVo)
     */
    @PostMapping("/add")
    @ResponseBody
    @ApiOperation(value = "添加系统蹲位信息", notes = "添加系统蹲位信息")
    @ApiImplicitParam(value = "positionInfoVo", name = "positionInfoVo", dataType = "com.beizhi.baseSystem.vo.PositionInfoVo", paramType = "query")
    public CommonResult addPositionInfo(PositionInfoVo positionInfoVo) {
        PositionInfo positionInfo = positionInfoService.saveOrEdit(positionInfoVo);
        return CommonResult.ok(positionInfoService.setOtherProperties(positionInfo));
    }

    /**
     * 修改系统蹲位信息
     *
     * @param positionInfoVo
     * @return CommonResult.ok(PositionInfoVo)
     */
    @PostMapping("/edit")
    @ResponseBody
    @ApiOperation(value = "修改系统蹲位信息", notes = "修改系统蹲位信息")
    @ApiImplicitParam(value = "positionInfoVo", name = "positionInfoVo", dataType = "com.beizhi.baseSystem.vo.PositionInfoVo", paramType = "query")
    public CommonResult editPositionInfo(PositionInfoVo positionInfoVo) {
        PositionInfo positionInfo = positionInfoService.saveOrEdit(positionInfoVo);
        return CommonResult.ok(positionInfoService.setOtherProperties(positionInfo));
    }

    /**
     * 逻辑删除系统蹲位信息
     *
     * @param positionInfoVo
     * @return CommonResult.ok(PositionInfoVo)
     */
    @PostMapping("/del")
    @ResponseBody
    @ApiOperation(value = "逻辑删除系统蹲位信息", notes = "逻辑删除系统蹲位信息")
    @ApiImplicitParam(value = "positionInfoVo", name = "positionInfoVo", dataType = "com.beizhi.baseSystem.vo.PositionInfoVo", paramType = "query")
    public CommonResult delPositionInfo(PositionInfoVo positionInfoVo) {
        PositionInfo positionInfo = positionInfoService.delById(positionInfoVo);
        return CommonResult.ok(positionInfoService.setOtherProperties(positionInfo));
    }

    /**
     * 逻辑删除系统用户信息
     *
     * @param ids
     * @return CommonResult.ok()
     */
    @PostMapping("/dels")
    @ResponseBody
    @ApiOperation(value = "逻辑删除系统蹲位信息", notes = "逻辑删除系统蹲位信息")
    @ApiImplicitParam(value = "ids", name = "ids", dataType = "java.util.List", paramType = "query")
    public CommonResult delUsers(@RequestParam("ids[]") List<String> ids) {
        PositionInfo positionInfo = new PositionInfo();
        positionInfoService.delByIds(ids, positionInfo);
        return CommonResult.ok();
    }

    /**
     * 真实删除系统蹲位信息
     *
     * @param positionInfoVo
     * @return CommonResult.ok()
     */
    @PostMapping("/delete")
    @ResponseBody
    @ApiOperation(value = "真实删除系统蹲位信息", notes = "真实删除系统蹲位信息")
    @ApiImplicitParam(value = "positionInfoVo", name = "positionInfoVo", dataType = "com.beizhi.baseSystem.vo.PositionInfoVo", paramType = "query")
    public CommonResult deletePositionInfo(PositionInfoVo positionInfoVo) {
        positionInfoService.trueDelById(positionInfoVo);
        return CommonResult.ok();
    }

    /**
     * 根据id查找系统蹲位信息
     *
     * @param positionInfoVo
     * @return CommonResult.ok(PositionInfoVo)
     */
    @GetMapping("/get")
    @ResponseBody
    @ApiOperation(value = "根据id查找系统蹲位信息", notes = "根据id查找系统蹲位信息")
    @ApiImplicitParam(value = "positionInfoVo", name = "positionInfoVo", dataType = "com.beizhi.baseSystem.vo.PositionInfoVo", paramType = "query")
    public CommonResult getPositionInfo(PositionInfoVo positionInfoVo) {
        PositionInfo positionInfo = positionInfoService.getById(positionInfoVo.getId());
        return CommonResult.ok(positionInfoService.setOtherProperties(positionInfo));
    }

    /**
     * 根据翻页参数、搜索参数查找系统蹲位信息
     *
     * @param positionInfoVo
     * @param page           当前第几页
     * @param rows           每页多少条记录
     * @return CommonResult.ok(PageInfo < PositionInfoVo >)
     */
    @GetMapping("/list")
    @ResponseBody
    @ApiOperation(value = "根据翻页参数、搜索参数查找系统蹲位信息", notes = "根据翻页参数、搜索参数查找系统蹲位信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "positionInfoVo", name = "positionInfoVo", dataType = "com.beizhi.baseSystem.vo.PositionInfoVo", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "page", dataType = "Integer", paramType = "path"),
            @ApiImplicitParam(name = "rows", value = "rows", dataType = "Integer", paramType = "path")
    })
    public CommonResult findPositionInfoList(PositionInfoVo positionInfoVo, Integer page, Integer rows) {
        PageInfo<PositionInfoVo> positionInfoVoPageInfo = positionInfoService.getByPositionInfo(positionInfoVo, page, rows);
        return CommonResult.ok(positionInfoVoPageInfo);
    }

    /**
     * 根据搜索参数查找所有系统蹲位信息
     *
     * @param positionInfoVo
     * @return CommonResult.ok(List < PositionInfoVo >)
     */
    @GetMapping("/getAll")
    @ResponseBody
    @ApiOperation(value = "根据搜索参数查找所有系统蹲位信息", notes = "根据搜索参数查找所有系统蹲位信息")
    @ApiImplicitParam(value = "positionInfoVo", name = "positionInfoVo", dataType = "com.beizhi.baseSystem.vo.PositionInfoVo", paramType = "query")
    public CommonResult getAllPositionInfo(PositionInfoVo positionInfoVo) {
        List<PositionInfoVo> positionInfoVoList = positionInfoService.getAllPositionInfo(positionInfoVo);
        return CommonResult.ok(positionInfoVoList);
    }

}
